package hehe.helper.convert;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by xfw on 17-4-3.
 */
public class MapFormat extends Convert
{
    public static Object parse(HashMap<String,Object> value, Field field)
    {
        ParameterizedType pt = (ParameterizedType)field.getGenericType();
        String valueType =  pt.getActualTypeArguments()[1].getTypeName();
        Map<String,Object> attrValue = new HashMap<>();

        for (Map.Entry<String, Object> vals : value.entrySet()) {
            try {
                Object value2 = Convert.format(valueType,vals.getValue(),field);
                attrValue.put(vals.getKey(),value2);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return attrValue;
    }
}
